<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="7" :lg="8" :md="9" :sm="24">
            <a-form-item label="数据日期">
              <j-date placeholder="请选择数据日期" :readOnly="true" v-model="queryParam.sjrq"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px;display:none">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('与业务状况表核数')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <js-ywzkb-modal ref="modalForm" @ok="modalFormOk"></js-ywzkb-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JsYwzkbModal from './modules/JsYwzkbModal'
  import { downFile, getAction } from '@api/manage'

  export default {
    name: 'JsYwzkbList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JsYwzkbModal
    },
    data () {
      return {
        description: '与业务状况表核数管理页面',
        vcode:'',
        // 表头
        columns: [
          {
            title:'数据日期',
            align:"center",
            dataIndex: 'sjrq',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'报表名称',
            align:"center",
            dataIndex: 'tbname'
          },
          {
            title:'科目',
            align:"center",
            dataIndex: 'km'
          },
          {
            title:'币种',
            align:"center",
            dataIndex: 'bz'
          },
          {
            title:'金数余额',
            align:"center",
            dataIndex: 'je'
          },
          {
            title:'总账余额',
            align:"center",
            dataIndex: 'zz'
          },
          {
            title:'差额',
            align:"center",
            dataIndex: 'ce'
          },
          {
            title:'金数数据条数',
            align:"center",
            dataIndex: 'sjts'
          },
        ],
        url: {
          list: "ywzkb/jsYwzkb/list",
          delete: "/ywzkb/jsYwzkb/delete",
          deleteBatch: "/ywzkb/jsYwzkb/deleteBatch",
          exportXlsUrl: "/ywzkb/jsYwzkb/exportXls",
          importExcelUrl: "ywzkb/jsYwzkb/importExcel",
          spywzkbUrl: "/ywzkb/jsYwzkb/spywzkb"
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      searchQuery1(vcode,vsjrq){
        this.vcode=vcode;
        this.queryParam.sjrq=vsjrq;
        var params=this.getQueryParams();
        this.queryParam.vcode=vcode;
        var that=this;
        var vurl=this.url.spywzkbUrl+"?vcode="+vcode;
        getAction(vurl,params).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.searchQuery();
          }
        });
      },
      searchQuery(){
        var params=this.getQueryParams();
        params['tbname']=this.vcode;
        var that=this;
        that.loading = true;
        getAction(this.url.list, params).then((res) => {
            if (res.success) {
              //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
              that.dataSource = res.result.records||res.result;
              if(res.result.total)
              {
                that.ipagination.total = res.result.total;
              }else{
                that.ipagination.total = 0;
              }
              //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            }else{
              that.dataSource = []
              that.ipagination.total = 0;
            }
          if(res.code===510){
            that.$message.warning(res.message)
          }
          that.loading = false;
        });
      },
      loadData(){
      },
      handleExportXls(fileName){
        if(!fileName || typeof fileName != "string"){
          fileName = "导出文件"
        }
        let param = this.getQueryParams();
        param['tbname']=this.vcode;
        console.log("导出参数",param)
        let downloadUrl = this.url.exportXlsUrl;
        downFile(downloadUrl,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'date',value:'sjrq',text:'数据日期'})
        fieldList.push({type:'string',value:'tbname',text:'报表名称'})
        fieldList.push({type:'string',value:'km',text:'科目'})
        fieldList.push({type:'string',value:'bz',text:'币种'})
        fieldList.push({type:'number',value:'je',text:'余额'})
        fieldList.push({type:'number',value:'zz',text:'zz'})
        fieldList.push({type:'number',value:'ce',text:'je-zz'})
        fieldList.push({type:'int',value:'sjts',text:'sjts'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>